<?php
namespace Core\CoreCommons;

/**
* The common service response
*
* @method ServiceResponse CreateError(Exception $ex)
*/
class ServiceResponse
{
	/**
	*  The response object
	*	
    *  @property object $response The object response to return at the end of the service call
    */
	public $response;
	
	/**
    *  @property boolean $isFailed The service detect an error
    */
	public $isFailed;
	
	/**
    *  @property string $exception The exception message
    */
	public $exception;
	
	/**
	*  The default constructor
	*
	* @param object $response The response to provide
	*
	*/
    public function __construct($response) 
	{
        $this->response = $response;
		$this->isFailed = false;
		$this->exception = null;
    }
	
	/**
	*	Create an error response
	*	
	*	@param Exception $ex The exception to throw 
	*/
	public static function CreateError(\Exception $ex)
	{
		Logger::Error($ex->getMessage());
		$serviceResponse = new ServiceResponse(null);
		$serviceResponse->isFailed = true;
		$serviceResponse->exception = $ex->getMessage();
		return $serviceResponse;
	}
}

?> 